package com.example.leetcode.high;

import java.util.HashMap;
import java.util.Map;

public class Solution3 {

    public static void main(String[] args) {
        int[] nums1 = {-1, -1}, nums2 = {-1, 1}, nums3 = {-1, 1}, nums4 = {1, -1};
        int i = new Solution3().fourSumCount(nums1, nums2, nums3, nums4);
        System.out.println(i);
    }

    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        int count = 0;
        Map<Integer, Integer> map = new HashMap<>();
        for (int a : nums1) {
            for (int b : nums2) {
                Integer sum = map.get(a + b);
                if(sum == null)sum=0;
                map.put(a + b, sum + 1);
            }
        }
        for (int c : nums3) {
            for (int d : nums4) {
                if (map.get(-(c + d)) != null) {
                    count += map.get(-(c + d));
                }
            }
        }
        return count;
    }
}
